# # 数据类型
# #整形 布尔型 浮点数 字符串 列表 元组 字典 集合
#
# #猜数字
#
# # import random
# # number = random.randint(1,100)
# # while True:
# #     guess = int(input("请输入数字："))
# #     if guess == number:
# #         print("恭喜你猜对了")
# #         break
# #     elif guess > number:
# #         print("你猜的数字太大了")
# #     else:
# #         print("你猜的数字太小了")
#
# # # 打印九九乘法表
# # for i in range(1,10):
# #     for j in range(1,i+1):
# #         print(i,"*",j,"=",i*j,end=" ")
# #         print(" ")
#
# # import turtle
# # turtle.pencolor("blue")
# # turtle.forward(100)
# # turtle.right(90)
# # turtle.forward(100)
# # turtle.right(90)
# # turtle.forward(100)
# # turtle.right(90)
# # turtle.forward(100)
# # turtle.done()
#
#
# import pygame
# # 使用pygame模块
# # 实现植物大战僵尸中僵尸动态行走
# # 图片路径：images/普通/1.png到22.png 共22张图片
#
# import os
# import sys
# #类 方法 函数
# # 构造函数会自动执行
# # 初始化pygame
# pygame.init()
#
# # 设置窗口大小
# screen_width = 1000
# screen_height = 600
# screen = pygame.display.set_mode((screen_width, screen_height))
# pygame.display.set_caption("Plants vs Zombies - Zombie Walking")
#
# # 加载僵尸行走动画帧
# zombie_frames = []
# for i in range(1, 23):  # 1.png 到 22.png
#     image_path = f"images/普通/{i}.png"
#     if os.path.exists(image_path):
#         img = pygame.image.load(image_path)
#         zombie_frames.append(img)
#     else:
#         print(f"警告: 找不到图片 {image_path}")
#
# if not zombie_frames:
#     print("错误: 没有找到任何僵尸动画帧图片")
#     sys.exit()
#
# # 设置游戏时钟
# clock = pygame.time.Clock()
#
# # 僵尸初始位置
# zombie_x = screen_width
# zombie_y = 300
# zombie_speed = 2
#
# # 动画控制
# frame_index = 0
# animation_speed = 0.2  # 控制动画速度
#
# # 游戏主循环
# running = True
# while running:
#     for event in pygame.event.get():
#         if event.type == pygame.QUIT:
#             running = False
#
#     # 更新僵尸位置
#     zombie_x -= zombie_speed
#     if zombie_x < -100:  # 如果僵尸走出屏幕左侧，重新从右侧进入
#         zombie_x = screen_width
#
#     # 更新动画帧
#     frame_index += animation_speed
#     if frame_index >= len(zombie_frames):
#         frame_index = 0
#
#     # 绘制
#     screen.fill((135, 206, 235))  # 蓝天背景
#
#     # 绘制僵尸
#     current_frame = zombie_frames[int(frame_index)]
#     screen.blit(current_frame, (zombie_x, zombie_y))
#
#     pygame.display.flip()
#     clock.tick(60)  # 60 FPS
#
# pygame.quit()

# import pygame
# # 使用pygame模块
# # 实现植物大战僵尸中向日葵在草地上动态摇摆
# # 向日葵图片路径：images/向日葵/1.png到18.png 共18张图片
# # 草地图片路径 = "images/beijing.png"
#
# import os
# import sys
#
#
# # 初始化pygame
# pygame.init()
#
# # 设置窗口大小
# screen_width = 1000
# screen_height = 600
# screen = pygame.display.set_mode((screen_width, screen_height))
# pygame.display.set_caption("Plants vs Zombies - Sunflower Animation")
#
# # 加载向日葵动画帧
# sunflower_frames = []
# for i in range(1, 19):  # 1.png 到 18.png
#     image_path = f"images/向日葵/{i}.png"
#     if os.path.exists(image_path):
#         img = pygame.image.load(image_path)
#         sunflower_frames.append(img)
#     else:
#         print(f"警告: 找不到图片 {image_path}")
#
# if not sunflower_frames:
#     print("错误: 没有找到任何向日葵动画帧图片")
#     sys.exit()
#
# # 设置游戏时钟
# clock = pygame.time.Clock()
#
# # 向日葵位置
# sunflower_x = 400
# sunflower_y = 200
#
# # 动画控制
# frame_index = 0
# animation_speed = 0.15  # 控制动画速度
#
# # 游戏主循环
# running = True
# while running:
#     for event in pygame.event.get():
#         if event.type == pygame.QUIT:
#             running = False
#
#     # 更新动画帧
#     frame_index += animation_speed
#     if frame_index >= len(sunflower_frames):
#         frame_index = 0
#
#     # 绘制
#     screen.fill((135, 206, 235))  # 蓝天背景
#
#     # 绘制向日葵
#     current_frame = sunflower_frames[int(frame_index)]
#     screen.blit(current_frame, (sunflower_x, sunflower_y))
#
#     pygame.display.flip()
#     clock.tick(60)  # 60 FPS
#
# pygame.quit()

# import pygame
# import os
# import sys
# import random
#
# # 初始化pygame
# pygame.init()
#
# # 设置窗口大小
# screen_width = 1000
# screen_height = 600
# screen = pygame.display.set_mode((screen_width, screen_height))
# pygame.display.set_caption("Plants vs Zombies - Multiple Zombies Walking")
#
# # 加载并缩放背景图片以铺满屏幕
# background_path = "images/beijing.jpg"
# background = None
# if os.path.exists(background_path):
#     # 加载背景并缩放到窗口大小
#     background = pygame.image.load(background_path)
#     background = pygame.transform.scale(background, (screen_width, screen_height))
# else:
#     print(f"警告: 找不到背景图片 {background_path}")
#
# # 加载僵尸行走动画帧
# zombie_frames = []
# for i in range(1, 23):  # 1.png 到 22.png
#     image_path = f"images/普通/{i}.png"
#     if os.path.exists(image_path):
#         img = pygame.image.load(image_path)
#         zombie_frames.append(img)
#     else:
#         print(f"警告: 找不到图片 {image_path}")
#
# if not zombie_frames:
#     print("错误: 没有找到任何僵尸动画帧图片")
#     sys.exit()
#
#
# # 僵尸类定义
# class Zombie:
#     def __init__(self, x, y):
#         self.x = x
#         self.y = y
#         self.speed = random.uniform(1, 3)  # 随机速度
#         self.frame_index = random.uniform(0, len(zombie_frames) - 1)  # 随机动画起始帧
#         self.animation_speed = random.uniform(0.1, 0.3)  # 随机动画速度
#
#     def update(self):
#         # 更新僵尸位置
#         self.x -= self.speed
#         if self.x < -100:  # 如果僵尸走出屏幕左侧，重新从右侧进入
#             self.x = screen_width + random.randint(0, 300)
#             self.y = random.randint(100, 400)  # 随机Y轴位置
#
#         # 更新动画帧
#         self.frame_index += self.animation_speed
#         if self.frame_index >= len(zombie_frames):
#             self.frame_index = 0
#
#     def draw(self, surface):
#         current_frame = zombie_frames[int(self.frame_index)]
#         surface.blit(current_frame, (self.x, self.y))
#
#
# # 创建多个僵尸实例
# zombies = []
# for i in range(5):  # 创建5个僵尸
#     zombie = Zombie(screen_width + i * 200, random.randint(100, 400))
#     zombies.append(zombie)
#
# # 设置游戏时钟
# clock = pygame.time.Clock()
#
# # 游戏主循环
# running = True
# while running:
#     for event in pygame.event.get():
#         if event.type == pygame.QUIT:
#             running = False
#
#     # 更新所有僵尸
#     for zombie in zombies:
#         zombie.update()
#
#     # 绘制背景（每次循环重新绘制背景，清除上一帧画面，防止僵尸留下痕迹）
#     if background:
#         screen.blit(background, (0, 0))  # 绘制铺满屏幕的背景
#     else:
#         screen.fill((135, 206, 235))  # 蓝天背景作为备选
#
#     # 绘制所有僵尸
#     for zombie in zombies:
#         zombie.draw(screen)
#
#     pygame.display.flip()
#     clock.tick(60)  # 60 FPS
#
# pygame.quit()


#使用pygame模型
# 实现植物大战僵尸中僵尸在背景上动态行走
# 向日葵图片路径：images/普通/1.png到22.png 共22张图片
# 背景图片路径 = "images/beijing.ipg"
# 鼠标变为锤子，锤子点击时，判断鼠标是否在 zombies列表中的某个僵尸的矩形范围内，如果是，则删除该僵尸
# 锤子图片路径为：images/hammer.png
# 当鼠标点击僵尸时，锤子将僵尸打没，一个僵尸打没后会有随机的阳光落下，阳光数量为1-4个，二十个阳光通关
# 阳光图片路径为：images/sun/1.png到22.png 共22张图片
# 导入所需模块
import pygame
import os
import sys
import random
import math

# 初始化pygame库，必须在使用pygame其他功能前调用
pygame.init()

# 设置游戏窗口尺寸
screen_width = 1000
screen_height = 600
# 创建游戏窗口
screen = pygame.display.set_mode((screen_width, screen_height))
# 设置窗口标题
pygame.display.set_caption("Plants vs Zombies - Zombie Game")

# 隐藏系统默认鼠标光标，后面会用锤子图片替代
pygame.mouse.set_visible(False)

# 游戏常量定义
ROW_COUNT = 5  # 车辆行数（共5辆）
ROW_SPACING = screen_height // (ROW_COUNT + 1)  # 计算行间距，使车辆均匀分布

# 加载并处理背景图片
background_path = "images/beijing.jpg"
background = None
if os.path.exists(background_path):
    # 加载背景图片并转换为适合pygame高效显示的格式
    background = pygame.image.load(background_path).convert()
    # 缩放背景图片以适应窗口大小
    background = pygame.transform.scale(background, (screen_width, screen_height))
else:
    print(f"警告: 找不到背景图片 {background_path}")
    # 如果找不到背景图，创建绿色表面作为替代
    background = pygame.Surface((screen_width, screen_height))
    background.fill((34, 139, 34))  # 绿色背景

# 加载游戏失败图片（僵尸胜利）
game_over_image = None
game_over_path = "images/ZombiesWon.jpg"
if os.path.exists(game_over_path):
    game_over_image = pygame.image.load(game_over_path).convert_alpha()
    # 缩放图片以适应屏幕
    game_over_image = pygame.transform.scale(game_over_image, (screen_width, screen_height))
else:
    print(f"警告: 找不到游戏失败图片 {game_over_path}")

# 加载锤子图片（鼠标光标）
hammer_path = "images/hammer.png"
hammer_image = None
if os.path.exists(hammer_path):
    # 加载带透明通道的锤子图片
    hammer_image = pygame.image.load(hammer_path).convert_alpha()
else:
    print(f"警告: 找不到锤子图片 {hammer_path}")
    # 创建简单矩形作为替代锤子
    hammer_image = pygame.Surface((30, 30), pygame.SRCALPHA)
    pygame.draw.rect(hammer_image, (139, 69, 19), (0, 0, 30, 30))

# 加载车辆图片
car_path = "images/车.png"
car_image = None
car_width = 80  # 预设车辆宽度
car_height = 50  # 预设车辆高度
if os.path.exists(car_path):
    car_image = pygame.image.load(car_path).convert_alpha()
    # 获取实际车辆图片尺寸
    car_width = car_image.get_width()
    car_height = car_image.get_height()
else:
    print(f"警告: 找不到车辆图片 {car_path}")
    # 创建灰色矩形作为替代车辆
    car_image = pygame.Surface((car_width, car_height), pygame.SRCALPHA)
    pygame.draw.rect(car_image, (100, 100, 100), (0, 0, car_width, car_height))

# 加载奖杯图片（通关奖励）
trophy_path = "images/trophy_hi_res.png"
trophy_image = None
if os.path.exists(trophy_path):
    trophy_image = pygame.image.load(trophy_path).convert_alpha()
    # 缩放奖杯图片
    trophy_image = pygame.transform.scale(trophy_image, (200, 250))
else:
    print(f"警告: 找不到奖杯图片 {trophy_path}")
    # 创建简单图形作为替代奖杯
    trophy_image = pygame.Surface((100, 150), pygame.SRCALPHA)
    pygame.draw.polygon(trophy_image, (255, 215, 0), [(50, 0), (100, 80), (50, 120), (0, 80)])
    pygame.draw.rect(trophy_image, (192, 192, 192), (30, 120, 40, 30))

# 加载僵尸行走动画帧（共22张）
zombie_frames = []
for i in range(1, 23):
    image_path = f"images/普通/{i}.png"
    if os.path.exists(image_path):
        img = pygame.image.load(image_path).convert_alpha()
        zombie_frames.append(img)
    else:
        print(f"警告: 找不到僵尸图片 {image_path}")

# 如果没有加载到任何僵尸图片，程序无法运行，退出
if not zombie_frames:
    print("错误: 没有找到任何僵尸动画帧图片")
    sys.exit()

# 加载阳光动画帧（共22张）
sun_frames = []
for i in range(1, 23):
    image_path = f"images/sun/{i}.png"
    if os.path.exists(image_path):
        img = pygame.image.load(image_path).convert_alpha()
        sun_frames.append(img)
    else:
        print(f"警告: 找不到阳光图片 {image_path}")

# 如果没有加载到任何阳光图片，程序无法运行，退出
if not sun_frames:
    print("错误: 没有找到任何阳光动画帧图片")
    sys.exit()


# 僵尸类定义
class Zombie:
    def __init__(self, x, y, row):
        self.x = x  # x坐标
        self.y = y  # y坐标
        self.row = row  # 所在行数（0-4）
        self.speed = random.uniform(1, 2.5)  # 随机移动速度
        self.frame_index = random.uniform(0, len(zombie_frames) - 1)  # 随机动画起始帧
        self.animation_speed = random.uniform(0.1, 0.3)  # 随机动画播放速度
        self.width = zombie_frames[0].get_width()  # 宽度（取自第一帧）
        self.height = zombie_frames[0].get_height()  # 高度（取自第一帧）
        self.hit = False  # 被击中状态标记
        self.hit_timer = 0  # 被击中计时器
        self.alive = True  # 是否存活

    def update(self):
        """更新僵尸状态（位置和动画）"""
        if not self.hit and self.alive:  # 只有存活且未被击中时移动
            self.x -= self.speed  # 向左移动

        # 更新动画帧索引
        self.frame_index += self.animation_speed
        # 动画循环播放
        if self.frame_index >= len(zombie_frames):
            self.frame_index = 0

        # 处理被击中状态（闪烁效果）
        if self.hit:
            self.hit_timer += 1
            # 10帧后结束被击中状态
            if self.hit_timer > 10:
                self.hit = False
                self.hit_timer = 0

    def draw(self, surface):
        """在指定表面上绘制僵尸"""
        if not self.alive:  # 已死亡则不绘制
            return

        # 获取当前动画帧
        current_frame = zombie_frames[int(self.frame_index)]
        if self.hit:
            # 被击中时闪烁（每隔一帧显示一次）
            if self.hit_timer % 2 == 0:
                surface.blit(current_frame, (self.x, self.y))
        else:
            surface.blit(current_frame, (self.x, self.y))

    def get_rect(self):
        """返回僵尸的碰撞矩形（用于检测点击和碰撞）"""
        return pygame.Rect(self.x, self.y, self.width, self.height)

    def set_hit(self):
        """设置僵尸为被击中状态"""
        self.hit = True
        self.hit_timer = 0

    def kill(self):
        """标记僵尸为死亡状态"""
        self.alive = False


# 阳光类定义
class Sun:
    def __init__(self, x, y):
        self.x = x  # x坐标
        self.y = y  # y坐标
        self.speed_y = random.uniform(1, 2)  # 下落速度
        self.oscillation = random.uniform(0, math.pi * 2)  # 随机初始摆动角度
        self.oscillation_speed = random.uniform(0.05, 0.1)  # 摆动速度
        self.frame_index = random.uniform(0, len(sun_frames) - 1)  # 随机动画起始帧
        self.animation_speed = random.uniform(0.1, 0.2)  # 随机动画速度
        self.width = sun_frames[0].get_width()  # 宽度
        self.height = sun_frames[0].get_height()  # 高度
        self.collected = False  # 是否被收集
        self.life_timer = 0  # 存在时间计时器
        self.max_life = 150  # 最大存在时间（60FPS*2.5秒）

    def update(self):
        """更新阳光状态（位置、动画和生命周期）"""
        if self.collected:  # 已收集则不更新
            return

        # 更新位置（下落并左右摆动）
        self.y += self.speed_y  # 向下移动
        self.oscillation += self.oscillation_speed  # 更新摆动角度
        self.x += math.sin(self.oscillation) * 0.8  # 基于正弦函数的水平摆动

        # 更新动画帧
        self.frame_index += self.animation_speed
        if self.frame_index >= len(sun_frames):
            self.frame_index = 0

        # 更新存在时间，超时自动消失
        self.life_timer += 1
        if self.life_timer > self.max_life or self.y > screen_height:
            self.collected = True

    def draw(self, surface):
        """绘制阳光"""
        if not self.collected:
            # 后期闪烁效果（快消失时闪烁提醒）
            if self.life_timer < self.max_life * 0.8 or self.life_timer % 4 < 2:
                current_frame = sun_frames[int(self.frame_index)]
                surface.blit(current_frame, (self.x, self.y))

    def get_rect(self):
        """返回阳光的碰撞矩形"""
        return pygame.Rect(self.x, self.y, self.width, self.height)

    def check_click(self, pos):
        """检查是否被鼠标点击，点击则标记为已收集"""
        if not self.collected and self.get_rect().collidepoint(pos):
            self.collected = True
            return True
        return False


# 车辆类定义
class Car:
    def __init__(self, x, y, row):
        self.x = x  # x坐标
        self.y = y  # y坐标
        self.row = row  # 所在行数
        self.original_x = x  # 初始位置（用于重置，当前版本未使用）
        self.active = True  # 是否可用（未触发）
        self.moving = False  # 是否正在移动
        self.speed = 10  # 滑行速度
        self.width = car_width  # 宽度
        self.height = car_height  # 高度

    def update(self):
        """更新车辆状态（移动状态）"""
        if self.moving:  # 只有正在移动时更新位置
            self.x += self.speed  # 向右移动
            # 如果车移出屏幕右侧，停止移动并标记为已使用
            if self.x > screen_width:
                self.moving = False
                self.active = False  # 车辆变为不可用

    def draw(self, surface):
        """绘制车辆（只有可用或正在移动时才绘制）"""
        if self.active or self.moving:
            surface.blit(car_image, (self.x, self.y))

    def get_rect(self):
        """返回车辆的碰撞矩形"""
        return pygame.Rect(self.x, self.y, self.width, self.height)

    def start_moving(self):
        """启动车辆（开始滑行）"""
        if self.active and not self.moving:  # 只有可用且未移动时才能启动
            self.moving = True


# 创建五辆汽车（左侧一列，每行一辆）
cars = []
for i in range(ROW_COUNT):
    # 计算每行车辆的Y坐标，使其垂直均匀分布
    car_y = ROW_SPACING * (i + 1) - car_height // 2
    car = Car(0, car_y, i)  # x=0表示放在最左侧
    cars.append(car)

# 创建初始僵尸（分布在不同行）
zombies = []
for i in range(10):
    row = random.randint(0, ROW_COUNT - 1)  # 随机行数
    # 计算该行僵尸的Y坐标（与对应行的车对齐）
    y_pos = ROW_SPACING * (row + 1) - zombie_frames[0].get_height() // 2
    # 从右侧生成僵尸，间隔150像素
    zombie = Zombie(screen_width + i * 150, y_pos, row)
    zombies.append(zombie)

# 阳光列表（存储所有当前存在的阳光）
suns = []

# 游戏状态变量
collected_suns = 0  # 已收集阳光数量
target_suns = 20  # 通关所需阳光数量
game_over = False  # 游戏是否结束
win = False  # 是否胜利

# 创建游戏时钟（控制帧率）
clock = pygame.time.Clock()

# 设置中文字体（确保中文正常显示）
try:
    font = pygame.font.Font("simhei.ttf", 32)  # 尝试加载黑体
except:
    # 备选字体列表
    font = pygame.font.SysFont(["SimHei", "Microsoft YaHei", "WenQuanYi Micro Hei"], 32)

# 游戏主循环
running = True
while running:
    # 获取当前鼠标位置
    mouse_pos = pygame.mouse.get_pos()

    # 事件处理
    for event in pygame.event.get():
        # 窗口关闭事件
        if event.type == pygame.QUIT:
            running = False
        # 鼠标点击事件（游戏未结束时有效）
        elif event.type == pygame.MOUSEBUTTONDOWN and not game_over:
            # 检查是否点击到僵尸
            for zombie in zombies[:]:  # 使用副本避免迭代时修改列表
                if zombie.alive and zombie.get_rect().collidepoint(mouse_pos):
                    zombie.set_hit()  # 标记为被击中（显示闪烁效果）
                    zombie.kill()  # 标记为死亡

                    # 生成随机数量的阳光（1-4个）
                    sun_count = random.randint(1, 4)
                    for _ in range(sun_count):
                        # 阳光生成位置在僵尸周围随机偏移
                        sun_x = zombie.x + random.randint(-20, zombie.width + 20)
                        sun_y = zombie.y + random.randint(-20, zombie.height + 20)
                        sun = Sun(sun_x, sun_y)
                        suns.append(sun)
                    break  # 一次点击只处理一个僵尸

            # 检查是否点击到阳光
            for sun in suns[:]:  # 使用副本避免迭代时修改列表
                if sun.check_click(mouse_pos):
                    suns.remove(sun)  # 从列表中移除
                    collected_suns += 1  # 增加收集数量

                    # 检查是否达到通关条件
                    if collected_suns >= target_suns:
                        game_over = True
                        win = True
                    break  # 一次点击只处理一个阳光

    # 游戏未结束时更新游戏状态
    if not game_over:
        # 更新所有僵尸
        for zombie in zombies[:]:
            if zombie.alive:
                zombie.update()

                # 检测僵尸是否碰到同一行的车
                for car in cars:
                    # 只检测可用且未移动的车，且与僵尸同属一行
                    if car.active and not car.moving and zombie.row == car.row:
                        # 碰撞检测
                        if zombie.get_rect().colliderect(car.get_rect()):
                            car.start_moving()  # 启动车辆

                            # 清除这一列（行）的所有僵尸
                            for z in zombies:
                                if z.alive and z.row == car.row:
                                    z.kill()  # 标记为死亡

                                    # 为被车撞死的僵尸生成阳光（1-2个）
                                    sun_count = random.randint(1, 2)
                                    for _ in range(sun_count):
                                        sun_x = z.x + random.randint(-10, z.width + 10)
                                        sun_y = z.y + random.randint(-10, z.height + 10)
                                        sun = Sun(sun_x, sun_y)
                                        suns.append(sun)

        # 更新所有车辆
        for car in cars:
            car.update()

        # 更新所有阳光（移除已收集的）
        for sun in suns[:]:
            sun.update()
            if sun.collected:
                suns.remove(sun)

        # 自动补充僵尸（保持一定数量的僵尸）
        # 统计当前存活的僵尸数量
        alive_zombies_count = len([z for z in zombies if z.alive])
        if alive_zombies_count < 8:  # 少于8个则补充
            row = random.randint(0, ROW_COUNT - 1)  # 随机行
            y_pos = ROW_SPACING * (row + 1) - zombie_frames[0].get_height() // 2
            # 从右侧随机位置生成新僵尸
            new_zombie = Zombie(screen_width + random.randint(0, 300), y_pos, row)
            zombies.append(new_zombie)

        # 检查车辆是否全部用完（没有可用车辆了）
        active_cars = any(car.active for car in cars)

        # 如果没有可用车辆，检查是否有僵尸突破到车后面的位置（x < 0）
        if not active_cars:
            for zombie in zombies:
                if zombie.alive and zombie.x < 0:  # 僵尸突破防线
                    game_over = True
                    win = False
                    break

    # 绘制背景
    screen.blit(background, (0, 0))

    # 绘制所有车辆
    for car in cars:
        car.draw(screen)

    # 绘制所有僵尸
    for zombie in zombies:
        zombie.draw(screen)

    # 绘制所有阳光
    for sun in suns:
        sun.draw(screen)

    # 绘制锤子光标（跟随鼠标位置）
    if hammer_image:
        # 使锤子图片中心对准鼠标位置
        hammer_x = mouse_pos[0] - hammer_image.get_width() // 2
        hammer_y = mouse_pos[1] - hammer_image.get_height() // 2
        screen.blit(hammer_image, (hammer_x, hammer_y))

    # 显示收集的阳光数量
    sun_text = font.render(f"阳光: {collected_suns}/{target_suns}", True, (255, 255, 0))
    screen.blit(sun_text, (10, 10))  # 左上角显示

    # 显示剩余车辆数量
    active_car_count = sum(1 for car in cars if car.active)  # 统计可用车辆
    car_text = font.render(f"剩余车辆: {active_car_count}", True, (255, 255, 255))
    screen.blit(car_text, (10, 50))  # 阳光数量下方显示

    # 游戏结束处理
    if game_over:
        if win:  # 胜利状态
            # 显示奖杯在屏幕中央
            trophy_x = screen_width // 2 - trophy_image.get_width() // 2
            trophy_y = screen_height // 2 - trophy_image.get_height() // 2
            screen.blit(trophy_image, (trophy_x, trophy_y))

            # 显示胜利文字
            win_text = font.render("恭喜通关!", True, (255, 215, 0))
            screen.blit(win_text, (screen_width // 2 - 80, screen_height // 2 + 150))
        else:  # 失败状态
            # 显示僵尸胜利的图片
            if game_over_image:
                screen.blit(game_over_image, (0, 0))  # 全屏显示
            else:
                # 没有失败图片时显示文字
                lose_text = font.render("游戏失败! 僵尸突破了防线", True, (255, 0, 0))
                screen.blit(lose_text, (screen_width // 2 - 200, screen_height // 2))

        # 显示退出提示
        restart_text = font.render("按ESC键退出", True, (255, 255, 255))
        # 根据是否有失败图片调整文字位置
        if not win and game_over_image:
            screen.blit(restart_text, (screen_width // 2 - 80, 50))  # 上方显示
        else:
            screen.blit(restart_text, (screen_width // 2 - 80, screen_height // 2 + 50))  # 中间下方

    # 检查ESC键退出
    keys = pygame.key.get_pressed()
    if keys[pygame.K_ESCAPE]:
        running = False

    # 更新屏幕显示
    pygame.display.flip()
    # 控制帧率为60FPS
    clock.tick(60)

# 退出游戏
pygame.quit()
sys.exit()